<template>
	<view>
		<view :style="bj" style="height: 150px;">
			<checkbox-group v-for="(item,index) in data" :key="index"
				style="float: right;margin-bottom: 10px;margin-right: 55px; border: 1px ;"
				@change="checkboxChange(item)">
				   <checkbox   type="checkbox"   :checked="item.val" :color="color">
					<text :style="fontcolor">{{item.key}}</text>
				</checkbox>
			</checkbox-group>
			<button :style="bt" @click="BillConvert"
				style="color: #FFFFFF;width:40%;float: left;height: 40px;">使用转换规则</button>
			<e-modal :visible.sync="visible" @cancel="handleCancel">
				<view v-for="(item,index) in convertList" :key="index" :style="bj">
					<view style="height: 40px" class="uni-form-item uni-column">
						<text :style="fontcolor" style="float: left;margin-top: 15px;">单据:{{item.fsourcename}}</text>
						<text :style="fontcolor" style="float: right;margin-top: 15px;">启用状态:{{item.fisuse}}</text>
					</view>
					<view style="height: 40px;color: red;" class="uni-form-item uni-column">
						<text style="float: left;margin-top: 15px;font-size: 15px;">转换规则:{{item.name}}</text>
					</view>
				</view>
				<view class="uni-btn-v">
					<button :style="bt" @click="handleCancel"
						style="color:#ffffff;width: 100%;float: right;">关闭</button>
				</view>
			</e-modal>
			<e-modal :visible.sync="visible1" @cancel="handleCancel1">
				<view class="uni-form-item uni-column">
					<view style="text-align: center;margin-bottom: 30px;">修改标题</view>
					<input :style="bor" v-model="obj.ftitle" style="height: 50px;" />
				</view>
				<view class="uni-btn-v">
					<button :style="bt" @click="confirmTitle" style="color:#ffffff;width: 50%;float: left;">保存</button>
					<button :style="bt" @click="handleCancel1"
						style="color:#ffffff;width: 50%;float: right;">关闭</button>
				</view>
			</e-modal>
		</view>
		<view style="font-size: 25rpx;color: red;">
			点击【标题】进入编辑,根据实际场景配置字段！
		</view>
		<view style="float: left;" class="teacher">
			<!-- 启动翻滚文字 -->
			<view class="teacher-list">
				<text id="btn" class="btn">标题</text>
				<text id="btn" class="btn">位置</text>
				<view class="btn">隐藏</view>
				<view class="btn">必录</view>
				<view class="btn">写入</view>
				<text class="btn">相机</text>
				<text class="btn">删除</text>
				<text class="btn">保留</text>
			</view>
		</view>
		<view style="float: left;" class="teacher">
			<view class="teacher-list" v-for="(item,index) in dataList" :key="index">
				<text id="btn" @click="EditField(item)" class="btn">{{item.ftitle}}</text>
				<text id="btn" class="btn">{{item.fname}}</text>
				<view class="btn">
					<checkbox-group @change="checkboxChange1(item,'fishidden')">
						                <checkbox                     type="checkbox"                   
							 :checked="item.fishidden" :color="color"                 >
							                 <text :style="fontcolor"></text>
							                </checkbox>
					</checkbox-group>
				</view>
				<view class="btn">
					<checkbox-group @change="checkboxChange1(item,'fmustinput')">
						                <checkbox                     type="checkbox"                   
							 :checked="item.fmustinput" :color="color"                 >
							                 <text :style="fontcolor"></text>
							                </checkbox>
					</checkbox-group>
				</view>
				<view class="btn">
					<checkbox-group @change="checkboxChange1(item,'fiswrite')">
						                <checkbox                     type="checkbox"                   
							 :checked="item.fiswrite" :color="color"                 >
							                 <text :style="fontcolor"></text>
							                </checkbox>
					</checkbox-group>
				</view>
				<text class="btn">
					<checkbox-group @change="checkboxChange1(item,'fiscamera')">
						                <checkbox                     type="checkbox"                   
							 :checked="item.fiscamera" :color="color"                 >
							                 <text :style="fontcolor"></text>
							                </checkbox>
					</checkbox-group>
				</text>
				<text class="btn">
					<checkbox-group @change="checkboxChange1(item,'fisshowdel')">
						                <checkbox                     type="checkbox"                   
							 :checked="item.fisshowdel" :color="color"                 >
							                 <text :style="fontcolor"></text>
							                </checkbox>
					</checkbox-group>
				</text>
				<text class="btn">
					<checkbox-group @change="checkboxChange1(item,'fisnosavelast')">
						                <checkbox                     type="checkbox"                   
							 :checked="item.fisnosavelast" :color="color"                 >
							                 <text :style="fontcolor"></text>
							                </checkbox>
					</checkbox-group>
				</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				obj: {},
				bor: {
					border: '1px dashed ' + this.$kdup.color
				},
				visible: false,
				visible1: false,
				eobj: {},
				bt: {
					backgroundColor: this.$kdup.color,
				},
				bj: {
					borderBottom: '1px dashed ' + this.$kdup.color
				},
				color: this.$kdup.color,
				fontcolor: {
					color: this.$kdup.color
				},
				data: [],
				dataList: [],
				convertList: []
			}
		},
		onLoad(e) {
			uni.setNavigationBarColor({
				frontColor: "#ffffff", //文字颜色
				backgroundColor: this.$kdup.color //底部背景色
			})
			//获取标题
			uni.setNavigationBarTitle({
				title: e.name + "-" + "配置",
			});
			this.initData(e.id);
			this.initfield(e.id);
			this.eobj = {};
			this.eobj = e;
		},
		methods: {
			confirmTitle() {
				if (this.obj.ftitle.trim() == "") {
					uni.showToast({
						title: "不能设置标题成空值！",
						icon: "none"
					});
				} else {
					var data = {
						sql: "update top_barcode_config_entry set FTITLE='" + this.obj.ftitle + "' where FEntryID=" +
							this.obj.fentryid
					}
					this.$myRequest.postRequest("LoadListJson", data).then(res => {
						uni.showToast({
							title: "修改成功！",
							icon: "none"
						});
						this.handleCancel1();
						this.initfield(this.eobj.id);
					})
				}
			},
			EditField(item) {
				this.visible1 = true
				this.obj = item;
			},
			handleCancel1() {
				if (this.obj.ftitle.trim() == "") {
			 	uni.showToast({
						title: "不能设置标题成空值！",
						icon: "none"
					});
					this.visible1 = true;
				} else {
					this.visible1 = false;
				}
			},
			handleCancel() {
				this.visible = false;
			},
			BillConvert() {
				var data = {
					sql: " select src.FSOURCENAME,CASE FISUSE WHEN '0' THEN '未启用'  ELSE '启用'  END as FISUSE, CASE  WHEN l.FNAME is null THEN '没有设置单据转换!'  ELSE l.FNAME  END as   name " +
						" from  top_SourceType_Entry src left join T_META_CONVERTRULE c on " +
						"  c.fid=src.FSRCCONVERTRULE left join T_META_CONVERTRULE_L l on l.FID=c.fid  where src.fid=" +
						this.eobj.id
				}
				this.$myRequest.postRequest("LoadListJson", data).then(res => {
					if (res.data.error == "") {
						//找到数据
						res.data.Table.pop();
						this.convertList = res.data.Table;
						this.visible = true;
					} else {
						//未找到数据
						uni.showToast({
							title: res.data.error,
							icon: "none"
						});
						return;
					}
				})
			},
			swicthType(name) {
				switch (name) {
					case "支持快速扫描":
						return "FASTSCAN"
						break;
					case "是否快速扫描":
						return "FASTSCANSTATUS"
						break;
					case "是否提交审核":
						return "FISCHECK"
						break;
					case "是否配套领料":
						return "FISPICKING"
						break;
					case "入库超额控制":
						return "FISEXCESS"
						break;
					case "是否控制状态":
						return "FISSTATUS"
						break;
					case "是否出库控制":
						return "FOUTCRTL"
						break;
				}
			},
			//勾选表体属性
			checkboxChange1: function(item, field) {
				var msg = "";
				if (field == "fishidden") {
					msg = "隐藏"
				} else if (field == "fmustinput") {
					msg = "必录"
				} else
				if (field == "fiswrite") {
					msg = "写入"
				} else if (field == "fiscamera") {
					msg = "相机"
				} else
				if (field == "fisshowdel") {
					msg = "删除"
				} else if (field == "fisnosavelast") {
					msg = "保留"
				}
				item[field] = !item[field];
				var data = {
					sql: "update top_barcode_config_entry set " + field + "=" + (item[field] == true ? 1 : 0) +
						" where fid=" + this.eobj.id + " and FEntryID=" + item.fentryid
				}
				this.$myRequest.postRequest("LoadListJson", data).then(res => {
					uni.showToast({
						title: item.ftitle + "已" + (item[field] == true ? "启用" : "关闭") + msg + "功能！",
						icon: "none"
					});
				})
			},
			//勾选表头属性
			checkboxChange: function(e) {
				for (var i = 0; i < this.data.length; i++) {
					if (this.data[i].key == e.key) {
						this.data[i].val = !e.val;
						var data = {
							sql: " update top_barcode_config set " + this.swicthType(e.key) + "=" + (this.data[i]
								.val == true ? 1 : 0) + "   where fid=" + this.eobj.id
						}
						this.$myRequest.postRequest("LoadListJson", data).then(res => {
							uni.showToast({
								title: "你已" + (e.val == true ? "启用" : "关闭") + e.key + "!",
								icon: "none"
							});
						})
					}
				}
			},
			initfield(id) {
				var str =
					"/*dialect*/select CASE FFIELDPOSITION WHEN '0' THEN '表头'  ELSE '表体'  END as fname, " +
					"  CASE FISHIDDEN WHEN '0' THEN 'false'  ELSE 'true'  END as FISHIDDEN, " +
					"  CASE FMUSTINPUT WHEN '0' THEN 'false'  ELSE 'true'  END as FMUSTINPUT, " +
					"  CASE FISWRITE WHEN '0' THEN 'false'  ELSE 'true'  END as FISWRITE, " +
					"  CASE FISCAMERA WHEN '0' THEN 'false'  ELSE 'true'  END as FISCAMERA, " +
					"  CASE FISSHOWDEL WHEN '0' THEN 'false'  ELSE 'true'  END as FISSHOWDEL, " +
					"  CASE FISNOSAVELAST WHEN '0' THEN 'false'  ELSE 'true'  END as FISNOSAVELAST, " +
					"  FEntryID fentryid, ftitle from top_barcode_config_entry where fid=" + id + " order by  fseq";
				var data = {
					sql: str
				}
				this.$myRequest.postRequest("LoadListJson", data).then(res => {
					if (res.data.error == "") {
						//找到数据
						res.data.Table.pop();
						for (var i = 0; i < res.data.Table.length; i++) {
							res.data.Table[i].fiscamera = res.data.Table[i].fiscamera == "false" ? false : true;
							res.data.Table[i].fishidden = res.data.Table[i].fishidden == "false" ? false : true;
							res.data.Table[i].fisnosavelast = res.data.Table[i].fisnosavelast == "false" ? false :
								true;
							res.data.Table[i].fisshowdel = res.data.Table[i].fisshowdel == "false" ? false : true;
							res.data.Table[i].fiswrite = res.data.Table[i].fiswrite == "false" ? false : true;
							res.data.Table[i].fmustinput = res.data.Table[i].fmustinput == "false" ? false : true;
						}
						this.dataList = res.data.Table;
					} else {
						//未找到数据
						uni.showToast({
							title: res.data.error,
							icon: "none"
						});
					}
				})
			},
			initData(id) {
				var str =
					" select CASE b.FASTSCAN  WHEN '0' THEN 'false'  ELSE 'true' END 支持快速扫描,CASE b.FASTSCANSTATUS WHEN '0' THEN 'false'  ELSE 'true' END 是否快速扫描,CASE b.FISCHECK WHEN '0' THEN 'false'  ELSE 'true' END 是否提交审核, " +
					" CASE b.FISPICKING WHEN '0' THEN 'false'  ELSE 'true' END 是否配套领料, CASE b.FISEXCESS WHEN '0' THEN 'false'  ELSE 'true' END 入库超额控制, " +
					" CASE b.FISSTATUS WHEN '0' THEN 'false'  ELSE 'true' END 是否控制状态,CASE b.FOUTCRTL WHEN '0' THEN 'false'  ELSE 'true' END 是否出库控制 " +
					" from  top_barcode_config b inner join top_barcode_config_L c on b.FID=c.FID  where FFORBIDSTATUS='A' and b.FID=" +
					id;
				var data = {
					sql: str
				}

				this.$myRequest.postRequest("LoadListJson", data).then(res => {
					if (res.data.error == "") {
						this.data = [];
						//找到数据
						res.data.Table.pop();
						for (var i = 0; i < Object.values(res.data.Table[0]).length; i++) {
							this.data.push({
								key: Object.keys(res.data.Table[0])[i],
								val: Object.values(res.data.Table[0])[i] == "false" ? false : true
							});
						}
					} else {
						//未找到数据
						uni.showToast({
							title: res.data.error,
							icon: "none"
						});
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.teacher {
		display: flex;
		flex-direction: column;
		align-items: center;

		.teacher-list {
			width: 650rpx;
			box-shadow: 0px 4px 14px 1px rgba(85, 85, 85, 0.08);
			background-color: #FFFFFF;
			border-radius: 10rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 30rpx;
			margin-top: 10rpx;

			.btn {
				width: 100rpx;
				height: 22rpx;
				border-radius: 20rpx;
				color: #000000;
				font-size: 20rpx;
				text-align: center;
				line-height: 42rpx;
			}

			.list-title {
				display: flex;
				align-items: center;

				.list-text {
					display: flex;
					flex-direction: column;
					margin-left: 23rpx;

					.title {
						color: #333333;
						font-size: 26rpx;
						font-weight: 500;
					}

					.content {
						color: #999999;
						font-size: 20rpx;
						margin-top: 28rpx;
						font-weight: 400;
					}
				}

				.image {
					width: 154rpx;
					height: 104rpx;
				}
			}
		}

		#btn {
			width: 100px;
		}

		&::after {
			content: "";
			position: fixed;
			z-index: -1;
			background-color: #F2F2F2;
			top: 0;
			left: 0;
			width: 100vw;
			height: 100vh;
		}
	}
</style>
